<template>
  <div>
    <echarts
      ref="charts"
      width="60%"
      height="600px"
    />
  </div>
</template>

<script>
import echarts from '@/components/echarts'
export default {
  name: 'student',
  components:{echarts},
  data() {
    return {
      option:{
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '5%',
          left: 'center',
          formatter:(name)=>{
            const arr = [
              {value: 1048, name: '搜索引擎'},
              {value: 735, name: '直接访问'},
              {value: 580, name: '邮件营销'},
              {value: 484, name: '联盟广告'},
              {value: 300, name: '视频广告'}
            ]
            for (let i=0;i<arr.length;i++){
              if (name===arr[i].name){
                return `${name}  ${arr[i].value}人`
              }
            }
          }
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              {value: 1048, name: '搜索引擎'},
              {value: 735, name: '直接访问'},
              {value: 580, name: '邮件营销'},
              {value: 484, name: '联盟广告'},
              {value: 300, name: '视频广告'}
            ]
          }
        ]
      }
    }
  },
  mounted() {
    this.$refs.charts.echartsInit(this.option)
  },
  methods: {}
}
</script>

<style scoped>

</style>
